package hotciv.variants;

import java.util.HashMap;

import hotciv.common.TileImpl;
import hotciv.framework.GameConstants;
import hotciv.framework.Position;
import hotciv.framework.Tile;
import hotciv.framework.TileMap;
import thirdparty.ThirdPartyFractalGenerator;

public class AdapterTileMap implements TileMap {
	private ThirdPartyFractalGenerator map;
	private HashMap<Position, Tile> tileMap;
	
	public AdapterTileMap() {
		map = new ThirdPartyFractalGenerator();
		tileMap = new HashMap<Position, Tile>();
	}

	@Override
	public Tile getTileAt(Position p) {
		if (tileMap.containsKey(p)) return tileMap.get(p);
		String type =  getTileType(map.getLandscapeAt(p.getRow(), p.getColumn()));
		Tile t = new TileImpl(p,type);
		tileMap.put(p, t);
		return t;
	}
	
	private String getTileType(char t) {
		if ( t == '.' ) return GameConstants.OCEANS;
        if ( t == 'o' ) return GameConstants.PLAINS;
        if ( t == 'M' ) return GameConstants.MOUNTAINS;
        if ( t == 'f' ) return GameConstants.FOREST;
        if ( t == 'h' ) return GameConstants.HILLS;
        return "";
	}
	
	
}
